﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Caipan
        //裁判
    {
        static Computer computer = new Computer();
        static Useplay user = new Useplay();
        public bool statr(String inputName, String computName)
        {
            int comWinCount = 0;
            int userWinCount = 0;
            bool flag = false;
            int count = 1;
            string j;
            Console.WriteLine("准备开始游戏了吗(y/n)");
            j = Console.ReadLine();
            if (j.Equals("y"))
            {
            m: do
                {
                    count++;
                    //玩家出拳
                    int userValue = user.getInputWhat();
                    Console.WriteLine(inputName + "出拳： ");
                    //电脑出拳
                    int comValue = computer.getInputWhat();
                    Console.WriteLine(computName + "出拳： ");
                    //裁判比较
                    int result = compare(comValue, userValue);
                    if (result == 1)
                    {
                        Console.WriteLine("笨蛋," + computName + "赢了");
                        comWinCount++;
                    }
                    else if (result == -1)
                    {
                        Console.WriteLine("笨蛋," + inputName + "赢了");
                        userWinCount++;
                    }
                    else
                    {
                        Console.WriteLine("嘿嘿，和局真衰，等着瞧吧");
                    }
                    Console.WriteLine("准备开始游戏了吗(y/n)");
                    j = Console.ReadLine();
                    switch (j)
                    {
                        case "y":
                            flag = true;
                            break;
                        case "n":
                            Console.WriteLine("==========================================");
                            Console.WriteLine(inputName + " VS " + computName);
                            Console.WriteLine("对战次数" + count);
                            Console.WriteLine();
                            Console.WriteLine("姓名\t\t得分");
                            Console.WriteLine(inputName + "\t\t" + userWinCount);
                            Console.WriteLine(computName + "\t\t" + comWinCount);
                            if (userWinCount > comWinCount)
                            {
                                Console.WriteLine(inputName + "赢");
                            }
                            else if (userWinCount > comWinCount)
                            {
                                Console.WriteLine(computName + "赢");
                            }
                            else
                            {
                                Console.WriteLine("平局");
                            }
                            Console.WriteLine("退出系统");
                            break;
                    }
                    goto m;
                } while (flag);
            }
            else if (j.Equals("n"))
            {
                Console.WriteLine("系统退出");
            }
            return flag;
        }
        public int compare(int computerValue, int userValue)
        {
            if (computerValue == userValue)
            {
                return 0;
            }
            else if (computerValue == 1)//1 剪刀
            {
                if (userValue == 2)//1 石头
                {
                    return -1;
                }
                else//3 布
                {
                    return 1;
                }
            }
            else if (computerValue == 2)//2 石头
            {
                if (userValue == 1)// 1 剪刀
                {
                    return 1;
                }
                else//3 布
                {
                    return -1;
                }
            }
            else//3 computerValue==布
            {
                if (userValue == 2)//石头
                {
                    return 1;
                }
                else// 1 剪刀
                {
                    return -1;
                }
            }
            //public enum Result
            //{
            //    电脑赢, 玩家赢, 平局
            //}
            //public static Result caipan(int playerNum, int cpuNum)
            //{
            //    if ((playerNum - cpuNum) == 1 || (playerNum - cpuNum) == -2)
            //        return Result.玩家赢;
            //    else if ((playerNum - cpuNum) == 0)
            //        return Result.平局;
            //    else
            //        return Result.电脑赢;
            //}
        }
    }
}
